<template>
	<view>
		<view style="display: flex;flex-direction:column;width: 90%;margin: 10rpx auto;">
			<text style="font-size: 28rpx;">选择班级1：</text>
			<view style="display: flex;align-items: center;">
				<uni-easyinput style="width: 620rpx;" type="text" v-model="kecheng" placeholder="请输入班级关键词"  />
				<picker @change="bindPickerChange"  :range="kechenglist_xiala">
					<uni-icons @click="kechengfun" style="font-size: 40rpx;margin-left:20rpx;" type="bottom"></uni-icons>
				</picker>
			</view>
		</view>
		<view style="width: 100%;height: 3rpx;background-color: gainsboro;">
			
		</view>
		<view style="display: flex;width: 90%;margin: 10rpx auto;">
			<uni-easyinput  type="textarea" v-model="neirong" placeholder="快来说点什么吧……" :inputBorder="false" />
		</view>
		<view style="display: flex;width: 90%; margin: 10rpx auto;">
			<uni-file-picker limit="9" title="请选择照片" :del-icon="true" mode="grid" v-model="imageValue" file-mediatype="image" @select="select"  @success="fanhuiurl" @delete="delpic"></uni-file-picker>
		</view>
		<view @click="fabu" style="display: flex;width: 40%;background-color: blue;color: white;border-radius: 20rpx;margin: 90rpx auto 0 auto;justify-content: center;align-items: center;padding: 10rpx 0;">
			发布
		</view>
	</view>
</template>

<script>
	import getDateTime from '@/common/getdateTime.js';
	export default {
		data() {
			return {
				isupload:0,
				kecheng:'',
				kechenglist:[],
				kechenglist_xiala:[],
				xinyunxin_userinfo:{},
				imageValue:[],
				neirong:''
			}
		},
		async onLoad() {
			this.xinyunxin_userinfo=await uniCloud.getCurrentUserInfo()
			console.log(this.xinyunxin_userinfo);
			this.kechengfun()
		},
		methods: {
			//选择课程
			bindPickerChange: function(e) {
				this.kecheng = this.kechenglist_xiala[e.detail.value]
				this.kechengid=this.kechenglist[e.detail.value]._id
			},
			// 获取课程
			kechengfun() {
				uni.showLoading({
					title: '课程信息获取…',
					mask: true
				});
				uniCloud.callFunction({
					name: "funshare",
					data: {
						leixing: 2, //获取我管理校区的课程
						id:this.xinyunxin_userinfo.uid,
						key:this.kecheng
					}
				}).then(res => {
					console.log(res);
					this.kechenglist=res.result.data
					this.kechenglist_xiala=[]
					res.result.data.map(item => {
						this.kechenglist_xiala.push(item.xiaoqu + '-'+ item.name)
					})
					uni.hideLoading()
				})
			},
			fabu(){
				if(this.neirong=='' || this.imageValue=='' || this.kecheng==''){
					uni.showToast({
						title: '未填写内容或未添加图片',
						icon: 'none',
						duration: 3000
					})
					return
				}
				if(this.isupload==0){
					uni.showToast({
						title: '图片上传中，请稍后',
						icon: 'none',
						duration: 3000
					})
					return
				}
				uni.showLoading({
					title:"发布中……"
				})
				uniCloud.callFunction({
					name:"pengyouquan",
					data:{
						huiyuanid:this.xinyunxin_userinfo.uid,
						neirong:this.neirong,
						tupianurl:this.imageValue,
						dianzanshu:15,
						fenlei:"班级",
						banjiid:this.kechengid,
						fabudate:getDateTime.dateTimeStr('y-m-d h:i:s')
					}
				}).then(res=>{
					uni.hideLoading()
					uni.navigateTo({
						url: '/pages/banjifengcai/banjifengcai'
					});
				})
			},
			delpic(e){
				console.log("要删除",e);
				uniCloud.callFunction({
					name:"delpic",
					data:{
						leixing:0,
						picurl:e.tempFile.fileID
					}
				}).then(res=>{
				})
			},
			select(){
				this.isupload=0
			},
			// 上传成功
			fanhuiurl(e){
				this.isupload=1
			}
		},
	}
</script>

<style>
page{
	/* background-color: #f8f8f8; */
}
</style>
